<?php
include '_init_.php';
	$orderManager = Order_Manager::getOrderManager($_REQUEST['id']);
if($orderManager == null)
	exit("Not exist");
if($orderManager->getStatus() != Order_Manager::$STATUS_SAVED)
	exit("Not allowed");
$orderManager->init();
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if($act == 'save')
{
	$discountInfo = false;
	$_REQUEST['type'] = isset($_REQUEST['type'])?$_REQUEST['type'][0]:'';
	if($_REQUEST['type'] == '折扣')
	{
		$discountInfo = array();
		$discountInfo['type'] =  $_REQUEST['discount_type'];
	}
	if ( !isset($_REQUEST['sales_list']) || !is_array($_REQUEST['sales_list'])) {
		$_REQUEST['sales_list'] = array();
	}
	if(intval($_REQUEST['pIndex']) > -1)
	{
		$orderManager->editPayOrder($_REQUEST['pIndex'],$_REQUEST['type'],$_REQUEST['amount'],implode(',',$_REQUEST['csr_list']),implode(',',$_REQUEST['sales_list']),$discountInfo,$_REQUEST['pay_method']);
	}else{
		$orderManager->addPayOrder($_REQUEST['type'],$_REQUEST['amount'],implode(',',$_REQUEST['csr_list']),implode(',',$_REQUEST['sales_list']),$discountInfo,$_REQUEST['pay_method']);
	}
	$orderManager->persistOrderInfo();
	AppMain::refreshParentFrame();
}

if($act == 'edit')
{
	$pIndex = intval($_REQUEST['pIndex']);
	$orderInfo = $orderManager->getInfo();
	$pamentInfo = $orderInfo['pay_list'][$pIndex];
}else{
	$_REQUEST['pIndex'] = -1;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/formvalidate.js"></script>
<script language="javascript">
$(function(){
//make radio select, only can select one
$('.jq_html_selector_type_list').change(function(){
/*
	if($('.jq_html_selector_type_list[value="折扣"]').attr('checked'))
	{
		$('#lbl_paytype').parent().attr('class','maina-1f3');
		$('#lbl_paytype').text('折扣金額');
	}else{
		$('#lbl_paytype').parent().attr('class','maina-1f');
		$('#lbl_paytype').text('付款金額');
	}*/
	$('.jq_html_selector_type_list').attr('checked',false);
	$(this).attr('checked',true);
	
});
$('.jq_html_selector_pay_method').change(function(){
	$('.jq_html_selector_pay_method').attr('checked',false);
	$(this).attr('checked',true);
	
});
<?php if($act == 'edit'):?>
$('input[name=amount]').val('<?php echo $pamentInfo['amount'];?>');
$('.jq_html_selector_type_list[value=<?php echo $pamentInfo['type'];?>]').attr('checked',true);

<?php foreach(explode(',',$pamentInfo['csr']) as $name):?>
$('.jq_html_selector_csr_list[value=<?php echo $name;?>]').attr('checked',true);
<?php endforeach;?>

<?php if(isset($pamentInfo['sales']) && strlen($pamentInfo['sales']) > 0):?>
<?php foreach(explode(',',$pamentInfo['sales']) as $name):?>
$('.jq_html_selector_sales_list[value=<?php echo $name;?>]').attr('checked',true);
<?php endforeach;?>
<?php endif;?>

<?php if(isset($pamentInfo['method'])):?>
$('.jq_html_selector_pay_method[value=<?php echo $pamentInfo['method'];?>]').attr('checked',true);
<?php else:?>
$('.jq_html_selector_pay_method[value=現金]').attr('checked',true);
<?php endif;?>

<?php else:?>
$('.jq_html_selector_pay_method[value=現金]').attr('checked',true);
<?php endif;?>

});
function checkForm(form)
{
	var tag = 0;
	if($('.jq_html_selector_csr_list:checked').length > 0)
	{	
		tag++;	
	}
	if($('.jq_html_selector_sales_list:checked').length > 0)
	{
		tag++;
	}
	
	if(tag == 0)
	{
		alert("請選擇客服人员或者門市人員!");
		return false;
	}
	if(tag == 2)
	{
		alert("只能够選擇客服人员或者門市人員!");
		return false;
	}
	form.submit();
	return false;
}
</script>
</head>

<body>
<form action="cosik.php">
<input type="hidden" name="act" value="save"/>
<input type="hidden" name="id" value="<?php echo $orderManager->getId();?>"/>
<input type="hidden" name="pIndex" value="<?php echo $_REQUEST['pIndex'];?>"/>
<div class="mainf-8">
   <ul>
  	 <li class="maina-1f2">付款方式</li>
   	<li class="mainf-1c"><input name="pay_method[]" type="checkbox" class="article-adminb-chbox jq_html_selector_pay_method"  value="現金"/>現金</li>
    <li class="mainf-1c"><input name="pay_method[]" type="checkbox" class="article-adminb-chbox jq_html_selector_pay_method"  value="刷卡"/>刷卡</li>
     
   </ul>
  <ul>
  		  <li class="maina-1f2">類别</li>  
        <li class="mainf-1c">
<input name="type[]" type="checkbox" class="article-adminb-chbox jq_html_selector_type_list"  value="預約"/>預約</li>
         <li class="mainf-1c">
<input name="type[]" type="checkbox" class="article-adminb-chbox jq_html_selector_type_list" value="拍照"/>拍照</li>
<li class="mainf-1c">
<input name="type[]" type="checkbox" class="article-adminb-chbox jq_html_selector_type_list" value="選片" />選片</li>
<li class="mainf-1c">
<input name="type[]" type="checkbox" class="article-adminb-chbox jq_html_selector_type_list" value="取件" />取件</li>
<li class="mainf-1c">
<input name="type[]" type="checkbox" class="article-adminb-chbox jq_html_selector_type_list" value="補訂金"/>補訂金</li>
<li class="mainf-1c2" style="width:300px;">
<input name="type[]" type="checkbox" class="article-adminb-chbox jq_html_selector_type_list" value="折扣"/>折扣
<select class="maine-keyinm" name="discount_type">
         <option value="優惠券">優惠券</option>
         <option value="消費折扣">消費折扣</option>
         <option value="生日優惠">生日優惠</option>
       </select>
</li>

<li class="maina-1f"><span id="lbl_paytype">付款金額</span><img src="images/line3.gif" width="21" height="12" />
<input name="amount" type="text"  class="maine-keyini2 _validate_form_float"/> </li>

<!--li class="maina-1f3"><span id="lbl_paytype">折扣金額</span><img src="images/line3.gif" width="21" height="12" />
<input name="discount_amount" type="text"  class="maine-keyini2 _validate_form_float"/> </li-->

<li class="maina-1f2">客服部</li>
 <?php
      	$dtWorder = new DataTable(constant('DB_TABLE_WORKER'));
      	$workerList = $dtWorder->get_list('`type`=2','name');
      	foreach($workerList as $tmpData)
      	{
      ?>
      	<li class="mainf-1c"><input type="checkbox" class="jq_html_selector_csr_list" name="csr_list[]" value="<?php echo $tmpData['name'];?>"/>&nbsp;<?php echo $tmpData['name'];?></li>
      <?php }?>
      
  
 
<li class="maina-1f2">門市人員</li>
 <?php
      	$dtWorder = new DataTable(constant('DB_TABLE_WORKER'));
      	$workerList = $dtWorder->get_list('`type`=1','name');
      	foreach($workerList as $tmpData)
      	{
      ?>
      	<li class="mainf-1c"><input type="checkbox" class="jq_html_selector_sales_list" name="sales_list[]" value="<?php echo $tmpData['name'];?>"/>&nbsp;<?php echo $tmpData['name'];?></li>
      <?php }?>     
      
  </ul>
</div>

<div class="mainf-7">
<ul>
<li class="article-1g"><input name="" type="button" class="article-1a_btn" value="儲存" onclick="return checkForm(this.form);"/></li>
</ul>
</div>
</form>
</body>
</html>
